#ifndef __COMPONENT_STARE_BEHAVIOR_H__
#define __COMPONENT_STARE_BEHAVIOR_H__

#include "ComponentBehavior.hpp"
#include "Engine/MathUtils.hpp"
#include "Engine/Vector2.hpp"

#include "EasyMachine.hpp"

using namespace PocketSurvival::Engine;

namespace PocketSurvival
{
    struct ComponentCreature;
    struct ComponentPathfinding;

    class SubsystemTimeOfDay;
    class SubsystemBodies;

    // 凝视行为

    struct ComponentStareBehavior : public ComponentBehavior
    {
    protected:
        enum class MachineState
        {
            Inactive,           // 不活跃的
            Stare
        };

        class StateMachine : public EasyMachine<MachineState>
        {
        private:
            ComponentStareBehavior * m_stareBehavior;
        public:
            StateMachine(ComponentStareBehavior *stareBehavior);

            virtual void enter() override;
            virtual void update(float dt) override;
            virtual void leave() override;
        };

    protected:
        float m_importanceLevel = 1.0f;
        float m_stareRange;
        double m_stareEndTime;
        entt::entity m_target;
        

        StateMachine *m_stateMachine;

    public:
        ComponentCreature *componentCreature;
        ComponentPathfinding *componentPathfinding;

        SubsystemTimeOfDay *subsystemTimeOfDay;
        SubsystemBodies *subsystemBodies;

        ComponentStareBehavior() = default;
        ~ComponentStareBehavior();

        virtual float getImportanceLevel() override;
        entt::entity findTarget();
        float scoreTarget(ComponentCreature *creature);


        virtual void update(float dt) override;
        virtual void load(const nlohmann::json &jsonData) override;
        virtual const std::string &getName() const override;
        static const std::string &GetName();
    };
}

#endif
